@extends('common.admin_template')

@section('content')
    <link rel="stylesheet" type="text/css" href="{{asset('css/daterangepicker.css')}}" />
    <?php
        $c=isset($_GET['cat'])?$_GET['cat']:'';
    ?>
    <div class="boxWidth">
        @include('common.notice_msg')
        <?php $role = array("0"=>"游客","2"=>"注册用户","3"=>"待审企业","4"=>"企业用户","5"=>"商户","8"=>"编辑","10"=>"管理员") ?>
        <div class="row searchLine">
            <div class="col-xs-6 ">
                选择时间：<input id="datefilter" type="text" name="datefilter" readonly  class="searchSelect" style="text-align: center" value="{{isset($_GET["start"])?$_GET["start"].'/'.$_GET["end"]:''}}">
                <select id="cat" class="searchSelect">
                    <option value="">全部分类</option>
                    @foreach($role as $k=>$r)
                        <option value="{{$k}}" @if($c==="$k") selected="selected"  @endif>{{$r}}</option>
                    @endforeach
                </select>
                <button class="btn btn-default searchBtn" id="searchMore">筛选</button>
                <a href="{{asset('excel/export?export=user'.(isset($_GET["start"])?'&start='.$_GET["start"].'&end='.$_GET["end"]:'').(isset($_GET["cat"])?'&cat='.$_GET["cat"]:'').(isset($_GET["page"])?'&page='.$_GET["page"]:''))}}"><button class="btn btn-default searchBtn">下载</button></a>
            </div>
            <div class="col-xs-6 searchInput">
                <input type="text" id="searchInput">
                <button class="btn btn-default searchBtn" id="searchCon">搜索</button>
            </div>
        </div>
            <table class="table table-hover adminTableBg">
                <thead>
                <tr>
                    <th class="col-xs-1">ID</th>
                    <th class="col-xs-2">用户名</th>
                    <th class="col-xs-2">邮箱</th>
                    <th class="col-xs-1">手机</th>
                    <th class="col-xs-1">真名</th>
                    <th class="col-xs-2">公司</th>
                    <th class="col-xs-1">角色</th>
                    <th class="col-xs-1 t_c">活动</th>
                    <th class="col-xs-1 t_c">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($Users as $user)
                    <tr>
                        <th class="col-xs-1 itemTd">{{$user->id}}</th>
                        <th class="col-xs-2 itemTd">{{$user->name}}</th>
                        <th class="col-xs-2 itemTd">{{$user->email}}</th>
                        <th class="col-xs-1 itemTd">{{$user->phone}}</th>
                        <th class="col-xs-1 itemTd">{{$user->real_name}}</th>
                        <th class="col-xs-2 itemTd">{{$user->company}}</th>
                        <th class="col-xs-1 itemTd">{{$role[$user->level]}}</th>
                        <th class="col-xs-1 itemTd t_c">{{$user->num}}</th>
                        <th class="col-xs-1 itemTd t_c">
                            <a href="{{url('admin/user/edit',['id' => $user->id])}}"><span id="addInput">编辑</span></a>
                        </th>
                    </tr>
                @endforeach
                </tbody>
            </table>
        <div class="pull-right">
            @if(!isset($_GET["start"]))
                <?php
                $s=isset($_GET['s'])?$_GET['s']:'';
                if($c){
                    $url = ['cat' => $c];
                }elseif($s){
                    $url = ['s' => $s];
                }else{
                    $url = [];
                }
                ?>
                {{$Users->render()}}
            @endif
        </div>
    </div>
@stop
@section('js')
    <script src="{{asset('js/moment.min.js')}}"></script>
    <script src="{{asset('js/daterangepicker.js')}}"></script>
    <script>
        $('input[name="datefilter"]').daterangepicker({
            autoUpdateInput: false,
            locale: {
                applyLabel: '确定',
                cancelLabel: '清除',
                fromLabel : '起始时间',
                toLabel : '结束时间',
                daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
                monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
                    '七月', '八月', '九月', '十月', '十一月', '十二月' ],
                firstDay : 1
            }
        });
        $('input[name="datefilter"]').on('apply.daterangepicker', function(ev, picker) {
            $(this).val(picker.startDate.format('YYYY-MM-DD') + '/' + picker.endDate.format('YYYY-MM-DD'));
        });

        $('input[name="datefilter"]').on('cancel.daterangepicker', function(ev, picker) {
            $(this).val('');
        });
        (function () {
            $('#searchCon').on('click',function () {
                var url = $('#searchInput').val().replace(/(^\s*)|(\s*$)/g, "");
                if(url){
                    window.location.href= "{!! url('admin/users?s=') !!}"+url;
                }else{
                    window.location.href= "{!! url('admin/users') !!}"
                }
            });
            $('#searchMore').on('click',function () {
                var t = $('#datefilter').val(),cat = $('#cat').val(),url = '{!! url('admin/users?') !!}';
                if(cat!==''){
                    url += 'cat='+cat+'&';
                }
                if(t){
                    var tArr = t.split('/'),start = tArr[0], end = tArr[1];
                    url += 'start='+start+'&'+'end='+end;
                }
                window.location.href= url
            });
        })()
    </script>
@stop